package ynu.edu.entity;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;
import org.springframework.util.DigestUtils;
import ynu.edu.common.entity.LogicEntity;

import javax.persistence.*;

@Entity
@Getter
@Setter
@Inheritance
@Where(clause = "is_deleted = 0")
@DiscriminatorColumn(name = "type")
public class User extends LogicEntity {
    @Transient
    public static final String TYPE_CUSTOMER = "0";
    @Transient
    public static final String TYPE_BUSINESS = "1";
    @Column(unique = true)
    protected String userPhone;

    @Column
    protected String username;

    @Column
    protected String password;

    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name="userAvatar", columnDefinition="longblob", nullable=true)
    private String userimage;

    @Transient
    public String token;

    /**
     * 创建所有User时，密码经过md5加密
     * @param psd
     */
//    public void setPassword(String psd){
//        this.password = DigestUtils.md5DigestAsHex(psd.getBytes());
//    }

    //顾客为0；商家为1
    @Column(updatable = false, insertable = false)
    protected String type;
}
